﻿using System;
using System.Collections.Generic;
using System.Linq;
using OutdoorLib.BaseEntity.Agency;
using OutdoorLib.BaseEntity.Dictionary;
using Grishko.DataTier;
using OutdoorLib.BaseEntity.Face;

    /// <summary>
    /// строчка настройки
    /// </summary>
    public class  SettingItem
    {
    
        public string ID {get;set;}
        public string DictionaryName {get;set;}
        public bool UseSystemDictionary{get;set;}

    }


    public static class AgencyExt
    {

        #region карта справочников
        /// <summary>
        /// Карта использования справочников 
        /// </summary>
        /// <param name="_Agency"></param>
        /// <returns></returns>
        public static List <SettingItem> GetTreeDictionarySettingsMap(this AgencyEntity  _Agency)
        {
            List<SettingItem> res = new List<SettingItem>();
            // список справочников
            EntityList lst = PageTools.GetDictionary(GlobalConstants.TreeDictionaryType);
            foreach (DictionaryItem item in lst)
            {
                if (item.ID == GlobalConstants.TreeDictionary_AdressProgram || item.ID == GlobalConstants.TreeDictionary_ConstractionType) continue;  
                bool isSystem = (_Agency.DictionarySettings[item.ID] == null);
                res.Add(new SettingItem() { ID = item.ID, DictionaryName = item.Value.ToString () , UseSystemDictionary = isSystem }); 
            }
            return res;
  
        }

        /// <summary>
        /// устанавливает или снимает значение в DictionarySettings
        /// </summary>
        /// <param name="?"></param>
        /// <param name="TreeDictionaryID"></param>
        public static void ReverceSetting_UseSystemDictionary(this AgencyEntity _Agency, string TreeDictionaryID) 
        {
            if (_Agency.DictionarySettings[TreeDictionaryID] == null) _Agency.DictionarySettings.Add(new EntitySingle() { ID = TreeDictionaryID });
            else
                _Agency.DictionarySettings.Remove(TreeDictionaryID);

        }

        
        #endregion

        #region адресные программы
       
        #endregion


       

        

    }

